import { h } from 'vue';
// import { Tag } from 'ant-design-vue';

import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'publicName',
  },
  {
    title: '键',
    dataIndex: 'publicKey',
  },
  {
    title: '值',
    dataIndex: 'publicValue',
  },
  // {
  //   title: '编码',
  //   dataIndex: 'validateCode',
  // },
  {
    title: '说明',
    dataIndex: 'summary',
  },
  {
    title: '类型',
    dataIndex: 'systemFlag',
    width: 150,
    customRender: ({ record }) => {
      const test = Number(record.systemFlag) === 0 ? '业务类' : '系统类';
      return h('div', test);
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 150,
    customRender: ({ record }) => {
      const status = record.typeStatus;
      const enable = ~~status === 0;
      const color = enable ? '#4DB803' : '#FF522B';
      const text = enable ? '正常' : '冻结';
      // return h(Tag, { color }, () => text);
      return h('div', { style: { display: 'flex', alignItems: 'center' } }, [
        h('div', {
          style: {
            width: '6px',
            height: '6px',
            backgroundColor: color,
            borderRadius: '50%',
            marginRight: '8px',
          },
        }),
        h('div', text),
      ]);
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'publicName',
    label: '名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'publicKey',
    label: '键名',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'systemFlag',
    label: '类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '业务类', value: '0' },
        { label: '系统类', value: '1' },
      ],
    },
    colProps: { span: 5 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'publicName',
    label: '名称',
    required: true,
    component: 'Input',
  },
  {
    field: 'publicKey',
    label: '键',
    required: true,
    component: 'Input',
  },
  {
    field: 'publicValue',
    label: '值',
    required: true,
    component: 'InputTextArea',
  },
  // {
  //   field: 'validateCode',
  //   label: '编码',
  //   component: 'Input',
  // },
  {
    field: 'systemFlag',
    label: '类型',
    component: 'Select',
    defaultValue: '0',
    required: true,
    componentProps: {
      allowClear: false,
      options: [
        { label: '业务类', value: '0' },
        { label: '系统类', value: '1' },
      ],
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    defaultValue: '0',
    required: true,
    componentProps: {
      allowClear: false,
      options: [
        { label: '正常', value: '0' },
        { label: '冻结', value: '9' },
      ],
    },
  },
  {
    field: 'publicType',
    label: '分组',
    component: 'Select',
    defaultValue: '1',
    required: true,
    componentProps: {
      allowClear: false,
      options: [
        { label: '检索', value: '1' },
        { label: '原文', value: '2' },
        { label: '报表', value: '3' },
        { label: '安全', value: '4' },
      ],
    },
  },
  {
    field: 'summary',
    label: '说明',
    // required: true,
    component: 'InputTextArea',
    colProps: {
      span: 24,
      lg: 24,
      md: 24,
    },
  },
];
